package com.ruoyi.iot.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iot.domain.FacDeviceFile;
import com.ruoyi.iot.service.IFacDeviceFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备封面照片Controller
 *
 * @author chenhs
 * @date 2024-09-28
 */
@RestController
@RequestMapping("/iot/deviceFile")
public class FacDeviceFileController extends BaseController
{
    @Autowired
    private IFacDeviceFileService facDeviceFileService;

    /**
     * 查询设备封面照片列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FacDeviceFile facDeviceFile)
    {
        startPage();
        List<FacDeviceFile> list = facDeviceFileService.selectFacDeviceFileList(facDeviceFile);
        return getDataTable(list);
    }

    /**
     * 导出设备封面照片列表
     */
    @Log(title = "设备封面照片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FacDeviceFile facDeviceFile)
    {
        List<FacDeviceFile> list = facDeviceFileService.selectFacDeviceFileList(facDeviceFile);
        ExcelUtil<FacDeviceFile> util = new ExcelUtil<FacDeviceFile>(FacDeviceFile.class);
        util.exportExcel(response, list, "设备封面照片数据");
    }

    /**
     * 获取设备封面照片详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(facDeviceFileService.selectFacDeviceFileById(id));
    }

    /**
     * 新增设备封面照片
     */
    @Log(title = "设备封面照片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FacDeviceFile facDeviceFile)
    {
        return toAjax(facDeviceFileService.insertFacDeviceFile(facDeviceFile));
    }

    /**
     * 修改设备封面照片
     */
    @Log(title = "设备封面照片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FacDeviceFile facDeviceFile)
    {
        return toAjax(facDeviceFileService.updateFacDeviceFile(facDeviceFile));
    }

    /**
     * 删除设备封面照片
     */
    @Log(title = "设备封面照片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(facDeviceFileService.deleteFacDeviceFileByIds(ids));
    }
}
